<!DOCTYPE html>
<html>
<head>
<title>修改试卷</title> <@h.head />
<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}
</style>
</head>
<body>
	<form id="fm" method="post"
		class="definewidth m20">
		<div style="text-align: center;" id="errorMsg"></div>
		<input type="hidden" id="id" value="${levelId!0}" name="id">
		<table class="table table-bordered table-hover definewidth m10">
			<tr>
				<td width="10%" class="tableleft">等级名称<span class="required">*</span></td>
				<td><input type="text" name="name" datatype="*" id="levelName"
						   nullmsg="请输入等级名称！" value="${dto.name}" /> <span class="Validform_checktip">请输入等级名称！</span></td>
			</tr>
			<tr>
				<td class="tableleft">说明文字</td>
				<td><input class="easyui-textbox" name="summary" style="height:60px" data-options="multiline:true" value="${dto.summary}"/></td>
			</tr>
			<tr>
				<td class="tableleft">考试时间</td>
				<td><input type="text" class="easyui-datebox" id="examTime" name="examTimeStr" value="${dto.examTime?string("yyyy-MM-dd")}"></td>
			</tr>
			<tr>
				<td class="tableleft">排序</td>
				<td><input type="text" name="showOrder" class="easyui-numberbox" value="${dto.showOrder}" /></td>
			</tr>
			<tr>
				<td class="tableleft"></td>
				<td>
					<button type="button" id="doSave" class="btn btn-primary" >保存</button>
					&nbsp;&nbsp;
					<button type="button" class="btn btn-success" onclick="goLevelList()">返回列表</button>
				</td>
			</tr>
		</table>
	</form>
	<form class="form-inline definewidth m20">
		<table class="table table-bordered table-hover definewidth m10">
			<tr>
				<td>
					<button type="button" class="btn btn-success" id="addClass">新增类别</button>
				</td>
			</tr>
		</table>
	</form>
	<!-- 试题列表 -->
	<form class="form-inline definewidth m20" action="${path}/classes/list" method="get" id="listForm">
		<input type="hidden" value="${levelId!0}" name="levelId">
		<table class="table table-bordered table-hover definewidth m10">
			<thead>
			<tr>
				<th style="width: 30px">序号</th>
				<th>类别名</th>
				<th>答题方式</th>
				<th>显示顺序</th>
				<th>创建时间</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			<#assign constant  = pagination.currentResult>
				<#list list as u>
					<#assign sum =u_index + constant + 1>
						<tr class="">
							<td>${(sum)!}</td>
							<td>${(u.name)!""}</td>
							<td>
								<#if u.method == 1>
									练习
									<#elseif u.method == 2>
									考试
								</#if>
							</td>
							<td>${(u.showOrder)}</td>
							<td>${(u.createdAt)?string("yyyy-MM-dd")}</td>
							<td>
								<a class="edit" href="${path}/class/modify?id=${(u.id)!''}">修改</a>
								<a class="edit" href="javascript:void(0)" onclick="delClasses(${(u.id)!0})">删除</a>
							</td>
						</tr>
				</#list>
			</tbody>
		</table>
		<@h.page />
	</form>
	<@h.foot />
	<script type="text/javascript">
		$('#addClass').click(function() {
            window.location.href = "${path}/class/add?levelId=${levelId!0}";
		});
        $('#doSave').click(function() {
            var examTime= $('#examTime').datebox('getValue');
            var levelName= $("#levelName").val();
            if(examTime==''){
                alert('请输入考试时间!');
                return;
            }
            if(levelName==''){
                alert('考试等级名称!');
                return;
            }

            var url = "${path}/level/update-level";
            $.ajax({
                cache: true,
                type: "POST",
                url: url,
                data:$('#fm').serialize(),// 你的formid
                async: false,
                error: function(request) {
                    alert("请求出问题.");
                },
                success: function(data) {
                    var myData = JSON.parse(data);
                    if (myData.status == 0) {
                        window.location.href = "${path}/level/list";
                    } else {
                        alert(myData.msg);
                    }
                }
            });

        });
        function delClasses(id) {
            if (confirm("确定删除该试题?")) {
                var url = "${path}/class/delete";
                $.ajax({
                    cache: true,
                    type: "POST",
                    traditional: true,
                    url: url,
                    data: {id:id},
                    async: false,
                    error: function (request) {
                        alert("请求出问题.");
                    },
                    success: function (data) {
                        var myData = JSON.parse(data);
                        if (myData.status == "0") {
                            window.location.href = "${path}/level/modify?id=${levelId!0}";
                        } else {
                            alert(data.status + "==" + data.msg);
                        }
                    }
                });
            }
        }
        function goLevelList() {
            window.location.href = "${path}/level/list";
        }
		var callback = function(data) {
			if (data.status == "0") {
				window.location.href = "${path}/level/modify?id=${levelId!0}";
			} else {
				$("#errorMsg").html(data.msg).show();
			}
		}
		$("#fm").validFrom(callback);
	</script>
</body>
</html>